//
//  MainHomeContractManageCell.m
//  ERP
//
//  Created by QA on 16/6/3.
//  Copyright © 2016年 ShangHai HaoLei Software Technology Co., Ltd. All rights reserved.
//

#import "MainHomeContractManageCell.h"
#import "WebViewController.h"
#import "GEPushViewControllerHelper.h"
#import "WWTBtnView.h"
#import "UIColorDispose.h"

@interface MainHomeContractManageCell ()

@property (nonatomic, strong) UINavigationController *navigationController;
@property (nonatomic, strong) NSArray *menuValueArray;

@property (nonatomic, strong) IBOutlet UIButton *button1;
@property (nonatomic, strong) IBOutlet UIButton *button2;
@property (nonatomic, strong) IBOutlet UIButton *button3;
@property (nonatomic, strong) IBOutlet UIButton *button4;
@property (nonatomic, strong) IBOutlet UIButton *button5;

@end

@implementation MainHomeContractManageCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
//        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MainHomeContractManageCell" owner:self options:nil];
//        self = [topLevelObjects objectAtIndex:1];
    }
    return self;
}

-(void)setMenuArray:(NSArray *)menuArray navigation:(UINavigationController*)navigation
{
    self.navigationController = navigation;
    self.menuValueArray = menuArray;
    
    CGFloat height = 250;
    UIView *_backView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SuperWidth, height)];
    [self addSubview:_backView1];
    
    //创建2个
    for (int i = 0; i < menuArray.count; i++) {
        ModuleAuthorityEntity *entity = [menuArray objectAtIndex:i];
        if (i < 2) {
            WWTBtnView *btnView = [[WWTBtnView alloc] initWithPingImageFrame:CGRectMake(0, i*height/2, SuperWidth/2, height/2)];
            [btnView setTitle:entity.title detail:entity.descripter imageStr:entity.icon];
            btnView.tag = i;
            btnView.detailLable.textColor = [UIColorDispose colorWithHexString:@"78808a"];
            btnView.titleLable.textColor = [UIColorDispose colorWithHexString:@"394042"];
            [_backView1 addSubview:btnView];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
            [btnView addGestureRecognizer:tap];
            
        } else if (i >= 2 && i<=5){
            WWTBtnView *btnView = [[WWTBtnView alloc] initWithMiniFrame:CGRectMake(SuperWidth/2, (i-2)*height/3, SuperWidth/2, height/3)];
            [btnView setTitle:entity.title detail:entity.descripter imageStr:entity.icon];
            btnView.tag = i;
            btnView.detailLable.textColor = [UIColorDispose colorWithHexString:@"78808a"];
            btnView.titleLable.textColor = [UIColorDispose colorWithHexString:@"394042"];
            [_backView1 addSubview:btnView];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
            [btnView addGestureRecognizer:tap];
        }
    }
    
    //绘制分割线
    UIView *lineView3 = [[UIView alloc] initWithFrame:CGRectMake(0, height/2, SuperWidth/2, 0.5)];
    lineView3.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView3];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(SuperWidth/2, 0, 0.5, height)];
    lineView.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView];
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(SuperWidth/2, height/3, SuperWidth/2, 0.5)];
    lineView1.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView1];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(SuperWidth/2, height/3*2, SuperWidth/2, 0.5)];
    lineView2.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView2];
}

-(void)setMenu2Array:(NSArray *)menuArray navigation:(UINavigationController*)navigation
{
    self.navigationController = navigation;
    self.menuValueArray = menuArray;
    
    CGFloat height = 210;
    CGFloat width = SuperWidth;
    UIView *_backView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SuperWidth, height)];
    [self addSubview:_backView1];
    
    //创建2个
    for (int i = 0; i < menuArray.count; i++) {
        ModuleAuthorityEntity *entity = [menuArray objectAtIndex:i];
        if (i < 2) {
            WWTBtnView *btnView = [[WWTBtnView alloc] initWithPingImageFrame:CGRectMake(i*width/2, 0, width/2, height/2)];
            [btnView setTitle:entity.title detail:entity.descripter imageStr:entity.icon];
            btnView.tag = i;
            btnView.detailLable.textColor = [UIColorDispose colorWithHexString:@"78808a"];
            btnView.titleLable.textColor = [UIColorDispose colorWithHexString:@"394042"];
            [_backView1 addSubview:btnView];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
            [btnView addGestureRecognizer:tap];
            
        } else if (i >= 2 && i<=5){
            WWTBtnView *btnView = [[WWTBtnView alloc] initWithVerticalFrame:CGRectMake((i-2)*width/3,height/2, SuperWidth/3, height/2 + 10)];
            [btnView setTitle:entity.title detail:entity.descripter imageStr:entity.icon];
            btnView.tag = i;
            btnView.detailLable.textColor = [UIColorDispose colorWithHexString:@"78808a"];
            btnView.titleLable.textColor = [UIColorDispose colorWithHexString:@"394042"];
            [_backView1 addSubview:btnView];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
            [btnView addGestureRecognizer:tap];
        }
    }
    
    //绘制分割线
    UIView *lineView3 = [[UIView alloc] initWithFrame:CGRectMake(0, height/2, width, 0.5)];
    lineView3.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView3];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(width/2, 0, 0.5, height/2)];
    lineView.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView];
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(SuperWidth/3, height/2, 0.5, height/2)];
    lineView1.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView1];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(SuperWidth/3*2, height/2, 0.5, height/2)];
    lineView2.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.25];
    [_backView1 addSubview:lineView2];
}

-(void)OnTapBtnView:(UITapGestureRecognizer *)sender
{
    NSLog(@"tag:%ld",sender.view.tag);
    
    ModuleAuthorityEntity *entity = [self.menuValueArray objectAtIndex:sender.view.tag];
    if(entity.codeType.integerValue == 1){
        //网页模式
        WebPushParameterModel *model = [[WebPushParameterModel alloc] init];
        model.URL = entity.webCode;
        model.Title = entity.title;
        model.CodeType = CodeTypeWeb;
        
        WebViewController *viewController = [[WebViewController alloc] initWithPushParameterModel:model];
        [self.navigationController pushViewController:viewController animated:YES];
    } else {
        //原生APP模式
        [GEPushViewControllerHelper pushViewControllerHomePageCode:entity.nativeCode navigation:self.navigationController];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
